package com.zqp.security.core.validator.code;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.zqp.security.core.properties.SecurityProperties;
import com.zqp.security.core.validator.code.image.ImageCodeGenerator;
import com.zqp.security.core.validator.code.sms.DefaultSmsSender;
import com.zqp.security.core.validator.code.sms.SmsCodeSender;


/**
 * 
* @author zqp
* @version2017年12月21日 
* @description
 */
@Configuration
public class ValidateCodeBeanConfig {
	
	@Autowired
	private SecurityProperties securityProperties;
	@Bean
	@ConditionalOnMissingBean(name="imageCodeGenerator")//如果有这个bean J就不会执行下面的了
	public ValidateCodeGenerator imageCodeGenerator() {
		ImageCodeGenerator codeGenerate = new ImageCodeGenerator();
		codeGenerate.setSecurityProperties(securityProperties);
		return codeGenerate;
	};
	@Bean
	@ConditionalOnMissingBean(SmsCodeSender.class)//用了这个接口的实现就不会用下面的实现了
	public SmsCodeSender smsCodeSender() {
		return new DefaultSmsSender();
	};
}
